<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <!-- <el-form-item label="设备端人员PID" prop="pid">
        <el-input
          v-model="queryParams.pid"
          placeholder="请输入设备端人员PID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->


      <!-- <el-form-item label="设备序列号" prop="deviceSn">
        <el-input
          v-model="queryParams.deviceSn"
          placeholder="请输入设备序列号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->

      <!-- 新增：摄像头位置查询 -->
      <el-form-item label="摄像头位置" prop="deviceSn">
        <el-select
          v-model="queryParams.deviceSn"
          placeholder="请选择摄像头位置"
          clearable
          style="width: 200px"
        >
          <el-option
            v-for="device in deviceOptions"
            :key="device.sn"
            :label="device.location"
            :value="device.sn"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员类别" prop="category">
        <el-select v-model="queryParams.category" placeholder="请选择人员类别" clearable>
          <el-option
            v-for="dict in dict.type.category"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-select v-model="queryParams.gender" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.gender"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="VIP等级" prop="vipLevel">
        <el-select v-model="queryParams.vipLevel" placeholder="请选择VIP等级" clearable>
          <el-option
            v-for="dict in dict.type.vip_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="最后到店时间" prop="lastVisit">
        <el-date-picker clearable
                        v-model="queryParams.lastVisit"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择最后到店时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['ry/customer:customer:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ry/customer:customer:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ry/customer:customer:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['ry/customer:customer:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-magic-stick"
          size="mini"
          :disabled="multiple"
          @click="handleBatchAIAnalyze"
        >批量AI分析
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="customerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!-- <el-table-column label="序号" align="center" prop="id"/> -->
      <!--
      <el-table-column label="设备端人员PID" align="center" prop="pid" />
      <el-table-column label="设备序列号" align="center" prop="deviceSn" /> -->
      <!-- <el-table-column label="摄像头位置" align="center" prop="deviceLocation"/> -->
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="人员类别" align="center" prop="category">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.category" :value="scope.row.category"/>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.gender" :value="scope.row.gender"/>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age"/>
      <el-table-column label="手机号" align="center" prop="phone"/>
      <el-table-column label="身份证号" align="center" prop="idCardNo"/>
      <el-table-column label="VIP等级" align="center" prop="vipLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.vip_level" :value="scope.row.vipLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="累计消费金额" align="center" prop="totalConsumption"/>
      <el-table-column label="微信用户" align="center" prop="openid"/>
      <el-table-column label="最后到店时间" align="center" prop="lastVisit" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastVisit, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="人脸照片" align="center" prop="facePhoto" width="100">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            trigger="hover"
            width="300"
          >
            <div>
              <img :src="scope.row.facePhoto" style="max-width: 100%; max-height: 300px;"/>
              <p v-if="scope.row.deviceLocation">设备位置：{{ scope.row.deviceLocation }}</p>
            </div>
            <image-preview slot="reference" :src="scope.row.facePhoto" :width="50" :height="50"/>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="备注信息" align="center" prop="remark"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['ry/customer:customer:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['ry/customer:customer:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改后的对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20"> <!-- 使用栅格布局 -->
          <!-- 左列 -->
          <el-col :span="12">
            <!-- <el-form-item label="设备端人员PID" prop="pid">
              <el-input v-model="form.pid" placeholder="请输入设备端人员PID" />
            </el-form-item>
            <el-form-item label="设备序列号" prop="deviceSn">
              <el-input v-model="form.deviceSn" placeholder="请输入设备序列号" />
            </el-form-item> -->

            <!-- 新增设备多选 -->
            <el-form-item label="摄像头位置" prop="deviceIds">
              <el-select
                v-model="form.deviceIds"
                multiple
                placeholder="请选择摄像头位置（可多选）"
                style="width: 100%"
                filterable
                default-first--option
              >
                <el-option
                  v-for="device in deviceOptions"
                  :key="device.sn"
                  :label="device.location"
                  :value="device.sn"
                />
              </el-select>
            </el-form-item>

            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名"/>
            </el-form-item>
            <el-form-item label="人员类别" prop="category">
              <el-select v-model="form.category" placeholder="请选择人员类别">
                <el-option
                  v-for="dict in dict.type.category"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="性别" prop="gender">
              <el-radio-group v-model="form.gender">
                <el-radio
                  v-for="dict in dict.type.gender"
                  :key="dict.value"
                  :label="parseInt(dict.value)"
                >{{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>

            <el-form-item label="年龄" prop="age">
              <el-select v-model="form.age" placeholder="请选择年龄">
                <el-option
                  v-for="age in ageOptions"
                  :key="age"
                  :label="age"
                  :value="age">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="手机号" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入手机号"/>
            </el-form-item>
          </el-col>
          <!-- 右列 -->
          <el-col :span="12">
            <el-form-item label="身份证号" prop="idCardNo">
              <el-input v-model="form.idCardNo" placeholder="请输入身份证号"/>
            </el-form-item>
            <el-form-item label="VIP等级" prop="vipLevel">
              <el-select v-model="form.vipLevel" placeholder="请选择VIP等级">
                <el-option
                  v-for="dict in dict.type.vip_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="累计消费金额" prop="totalConsumption">
              <el-input v-model="form.totalConsumption" placeholder="请输入累计消费金额"/>
            </el-form-item>
            <el-form-item label="最后到店时间" prop="lastVisit">
              <el-date-picker clearable
                              v-model="form.lastVisit"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择最后到店时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="人脸照片" prop="facePhoto">
              <image-upload v-model="form.facePhoto"
                            :limit="1"
              />
            </el-form-item>
            <el-form-item label="备注信息" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注信息"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>

    </el-dialog>

    <!-- 批量AI分析对话框 -->
    <el-dialog :title="batchAIAnalyzeDialogTitle" :visible.sync="batchAIAnalyzeDialogVisible" width="600px"
               append-to-body
               :close-on-click-modal="false">
      <el-form :model="batchAIAnalyzeForm" ref="batchAIAnalyzeForm" label-width="80px">
        <el-form-item label="AI结果">
          <el-input
            v-model="batchAIAnalyzeForm.result"
            type="textarea"
            :rows="6"
            placeholder="AI分析结果将显示在这里"
            ref="batchAIResultInput"
          ></el-input>
        </el-form-item>
      </el-form>

      <el-form :model="batchAIAnalyzeForm" ref="batchAIAnalyzeForm" label-width="80px" style="margin-top: 20px;">
        <el-form-item label="提示词">
          <el-input
            v-model="batchAIAnalyzeForm.prompt"
            type="textarea"
            :rows="4"
            placeholder="请输入AI分析的提示词，如：请根据客户ID123,456的消费记录，生成批量分析报告。"
          ></el-input>
          <el-button type="primary" size="mini" style="margin-top: 8px; float: right;"
                     @click="sendBatchAIAnalyzeRequest" :loading="batchAIAnalyzeLoading">发送
          </el-button>
        </el-form-item>
        <el-form-item>
          <div style="margin-top: 10px;">
            <el-tag
              v-for="tag in displayedPromptTags"
              :key="tag.promptId"
              effect="plain"
              size="small"
              style="margin-right: 10px; cursor: pointer;"
              @click="handleTagClickBatch(tag.content)"
            >
              {{ tag.title }}
            </el-tag>
          </div>
          <div v-if="aiPromptList.length > maxVisiblePromptTags">
            <el-link
              v-if="!showAllPromptTags"
              type="primary"
              :underline="false"
              @click="toggleShowAllPromptTags"
              style="margin-top: 5px;"
            >展开更多
            </el-link>
            <el-link
              v-else
              type="primary"
              :underline="false"
              @click="toggleShowAllPromptTags"
              style="margin-top: 5px;"
            >收起
            </el-link>
          </div>
        </el-form-item>

        <!-- 新增AI模型选择下拉框 -->
        <el-form-item label="选择模型" prop="selectedAiModel">
          <el-select
            v-model="batchAIAnalyzeForm.selectedAiModel"
            placeholder="请选择AI模型"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="model in aiModelOptions"
              :key="model.id"
              :label="model.modelName"
              :value="model.modelName"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelBatchAIAnalyzeDialog">取消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  listCustomer,
  getCustomer,
  delCustomer,
  addCustomer,
  updateCustomer,
  streamBatchAnalyzeCustomerAI
} from "@/api/ry/customer/customer"
import {listDevice} from "@/api/student/device/device"; // 设备API
import {listPrompts} from "@/api/ry/prompts/prompts";
import {listAiModel} from "@/api/ry/aiModel/aiModel"; // 新增：AI模型API

export default {
  name: "Customer",
  dicts: ['vip_level', 'category', 'gender'],
  data() {
    return {
      deviceOptions: [], // 设备列表
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 核心人员信息表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pid: null,
        deviceSn: null,
        name: null,
        category: null,
        gender: null,
        vipLevel: null,
        lastVisit: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deviceIds: [
          {required: true, message: "请至少选择一个设备", trigger: "change"},
          {type: 'array', min: 1, message: '请至少选择一个设备', trigger: 'change'}
        ],
        name: [
          {required: true, message: "姓名不能为空", trigger: "blur"}
        ],
        age: [
          { required: true, message: "请选择年龄", trigger: "change" }
        ],
      },
      // 批量AI分析对话框相关数据
      batchAIAnalyzeDialogVisible: false,
      batchAIAnalyzeDialogTitle: '批量AI分析',
      batchAIAnalyzeLoading: false,
      batchAIAnalyzeController: null,
      batchAIAnalyzeForm: {
        prompt: '',
        result: '',
        selectedAiModel: '' // 新增：选中的AI模型
      },
      // 批量AI分析表单校验
      batchAIAnalyzeRules: {
        selectedAiModel: [
          {required: true, message: "请选择AI模型", trigger: "change"}
        ]
      },
      aiPromptList: [], // 存储从后端获取的AI提示词列表
      maxVisiblePromptTags: 5, // 默认显示的标签数量
      showAllPromptTags: false, // 控制是否显示所有标签
      aiModelOptions: [], // 新增：AI模型列表
      ageOptions: [], // 新增：年龄选项列表
    }
  },
  computed: {
    // 计算属性：根据showAllPromptTags决定显示多少标签
    displayedPromptTags() {
      return this.showAllPromptTags ? this.aiPromptList : this.aiPromptList.slice(0, this.maxVisiblePromptTags);
    }
  },
  created() {
    this.getList();
    this.getDeviceList(); // 加载设备列表
    this.getAiPromptList(); // 新增：获取AI提示词列表
    this.getAiModelList(); // 新增：获取AI模型列表
    this.getAgeOptions(); // 新增：获取年龄选项列表
  },
  watch: {
    'batchAIAnalyzeForm.result': function (newVal, oldVal) {
      this.$nextTick(() => {
        const textarea = this.$refs.batchAIResultInput ? this.$refs.batchAIResultInput.$refs.textarea : null;
        if (textarea) {
          textarea.scrollTop = textarea.scrollHeight;
        }
      });
    }
  },
  methods: {
    // 新增：获取设备列表
    getDeviceList() {
      listDevice({
        pageNum: 1,
        pageSize: 1000
      }).then(response => {
        this.deviceOptions = response.rows;
      });
    },
    /** 查询核心人员信息列表 */
    getList() {
      this.loading = true
      listCustomer(this.queryParams).then(response => {
        this.customerList = response.rows.map(customer => {
          // 将设备SN转换为位置名称
          const device = this.deviceOptions.find(d => d.sn === customer.deviceSn);
          return {
            ...customer,
            deviceLocation: device ? device.location : "未知位置"
          };
        });
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pid: null,
        deviceSn: null,
        name: null,
        category: null,
        gender: null,
        age: null,
        phone: null,
        idCardNo: null,
        vipLevel: null,
        totalConsumption: null,
        openid: null,
        lastVisit: null,
        facePhoto: null,
        remark: null,
        lastAppearTime: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        deviceIds: [] // 初始化设备ID数组
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加核心人员信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getCustomer(id).then(response => {
        // 先清除deviceId字段，防止干扰deviceSn
        if (response.data.deviceId) {
          // 确保设备序列号字段正确赋值
          response.data.deviceSn = response.data.deviceSn || response.data.deviceId
          // 删除deviceId字段，避免混淆
          delete response.data.deviceId
        }
        this.form = response.data
        console.log("获取的客户数据(处理后):", this.form)
        this.open = true
        this.title = "修改核心人员信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 删除可能的deviceId属性，避免干扰
          if (this.form.deviceId) {
            delete this.form.deviceId
          }

          // 提交前检查deviceSn值
          console.log("提交的表单数据:", JSON.stringify(this.form))

          if (this.form.id != null) {
            updateCustomer(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            }).catch(error => {
              console.error("更新失败:", error)
            })
          } else {
            addCustomer(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            }).catch(error => {
              console.error("添加失败:", error)
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除核心人员信息编号为"' + ids + '"的数据项？').then(function () {
        return delCustomer(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ry/customer/customer/export', {
        ...this.queryParams
      }, `customer_${new Date().getTime()}.xlsx`)
    },
    /** 批量AI分析按钮操作 */
    handleBatchAIAnalyze() {
      this.batchAIAnalyzeDialogVisible = true;

      // 获取选中的客户名称列表
      const selectedCustomerNames = this.ids.map(id => {
        const customer = this.customerList.find(c => c.id === id);
        return customer ? customer.name : `ID:${id}`;
      });
      this.batchAIAnalyzeForm.prompt = `请对客户: ${selectedCustomerNames.join(', ')} 进行批量AI分析。`;
      this.batchAIAnalyzeForm.result = ''; // 清空上一次的分析结果
    },
    // 发送批量AI分析请求
    async sendBatchAIAnalyzeRequest() {
      if (!this.batchAIAnalyzeForm.prompt) {
        this.$modal.msgWarning("请输入AI分析提示词！");
        return;
      }
      if (!this.batchAIAnalyzeForm.selectedAiModel) {
        this.$modal.msgWarning("请选择AI模型！");
        return;
      }
      // 新增：表单校验
      this.$refs.batchAIAnalyzeForm.validate(async valid => {
        if (valid) {
          if (this.batchAIAnalyzeLoading) return;

          this.batchAIAnalyzeLoading = true;
          this.batchAIAnalyzeForm.result = '';
          if (this.batchAIAnalyzeController) this.batchAIAnalyzeController.abort();
          this.batchAIAnalyzeController = new AbortController();

          try {
            const reader = await streamBatchAnalyzeCustomerAI({
              customerIds: this.ids,
              prompt: this.batchAIAnalyzeForm.prompt,
              modelName: this.batchAIAnalyzeForm.selectedAiModel // 修改：将参数名称改为 modelName
            }, this.batchAIAnalyzeController.signal);

            const decoder = new TextDecoder('utf-8');
            let done = false;
            let aiText = '';
            while (!done) {
              const {value, done: doneReading} = await reader.read();
              done = doneReading;
              if (value) {
                aiText += decoder.decode(value, {stream: !done});
                this.batchAIAnalyzeForm.result = aiText;
              }
            }
          } catch (err) {
            if (err.name === 'AbortError') {
              console.log('批量AI分析请求已取消');
            } else {
              this.$message.error('批量AI分析失败');
              console.error('批量AI分析错误:', err);
            }
          } finally {
            this.batchAIAnalyzeLoading = false;
            this.batchAIAnalyzeController = null;
          }
        }
      });
    },
    // 取消批量AI分析对话框
    cancelBatchAIAnalyzeDialog() {
      this.batchAIAnalyzeDialogVisible = false;
      if (this.batchAIAnalyzeController) {
        this.batchAIAnalyzeController.abort();
        this.batchAIAnalyzeController = null;
      }
      this.batchAIAnalyzeForm.prompt = '';
      this.batchAIAnalyzeForm.result = '';
    },
    // 处理标签点击事件
    handleTagClickBatch(content) {
      if (this.ids.length === 0) {
        this.$modal.msgWarning("请先选择客户！");
        return;
      }
      // 获取选中的客户名称列表
      const selectedCustomerNames = this.ids.map(id => {
        const customer = this.customerList.find(c => c.id === id);
        return customer ? customer.name : `ID:${id}`;
      });
      // 将占位符替换为实际的客户ID和客户名称
      let finalPrompt = content.replace(/{customerIds}/g, selectedCustomerNames.join(', '));
      this.batchAIAnalyzeForm.prompt = finalPrompt;
    },
    // 新增：获取AI提示词列表
    getAiPromptList() {
      listPrompts({pageNum: 1, pageSize: 100000}).then(response => {
        this.aiPromptList = response.rows || [];
      }).catch(error => {
        console.error("获取AI提示词列表失败", error);
        this.$modal.msgError("获取AI提示词列表失败");
      });
    },
    // 新增：切换显示所有提示词标签
    toggleShowAllPromptTags() {
      this.showAllPromptTags = !this.showAllPromptTags;
    },
    // 新增：获取AI模型列表
    getAiModelList() {
      listAiModel({pageNum: 1, pageSize: 100000}).then(response => {
        this.aiModelOptions = response.rows || [];
      }).catch(error => {
        console.error("获取AI模型列表失败", error);
        this.$modal.msgError("获取AI模型列表失败");
      });
    },
    // 新增：获取年龄选项列表
    getAgeOptions() {
      const ages = [];
      for (let i = 1; i <= 100; i++) {
        ages.push(i);
      }
      this.ageOptions = ages;
    },
  }
}
</script>
<style scoped>
/* 添加间距优化 */
.el-form-item {
  margin-bottom: 18px;
}
</style>
